<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head th:replace="~{segmentation/_right_bottom_header::_header_common(~{::title},~{::link},~{::style})}">
    <meta charset="utf-8">
    <title>地区编辑</title>
    <link>
    <style type="text/css"></style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>地区编辑</legend>
        </fieldset>
        <form class="layui-form" id="districtFormEdit" action="">
            <input type="hidden" id="id" name="id" th:value="${p.id}"/>
<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label"><span class="required-red">*</span>等级-->
<!--                </label>-->
<!--                <div class="layui-input-block">-->
<!--                    <input type="text" name="level" id="level" lay-verify="required|number|level"-->
<!--                           lay-verType="tips"-->
<!--                           th:value="${p.level}"-->
<!--                           placeholder="请输入等级" autocomplete="off" class="layui-input">-->
<!--                </div>-->
<!--            </div>-->
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>上级区划</label>
                <div class="layui-input-block">
                    <span class="view-span" th:text="${p.parentName}"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>区划名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" lay-verify="required|name"
                           lay-verType="tips"
                           th:value="${p.name}"
                           placeholder="请输入区划名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>区划编码</label>
                <div class="layui-input-block">
                    <span class="view-span" th:text="${p.code}"></span>
                </div>
            </div>
<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label"><span class="required-red">*</span>地区全拼音-->
<!--                </label>-->
<!--                <div class="layui-input-block">-->
<!--                    <input type="text" name="pinYin" id="pinYin" lay-verify="required|pinYin"-->
<!--                           lay-verType="tips"-->
<!--                           th:value="${p.pinYin}"-->
<!--                           placeholder="请输入地区全拼音" autocomplete="off" class="layui-input">-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label"><span class="required-red">*</span>区域第一个字的首字母-->
<!--                </label>-->
<!--                <div class="layui-input-block">-->
<!--                    <input type="text" name="initial" id="initial" lay-verify="required|initial"-->
<!--                           lay-verType="tips"-->
<!--                           th:value="${p.initial}"-->
<!--                           placeholder="请输入区域第一个字的首字母" autocomplete="off" class="layui-input">-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label"><span class="required-red">*</span>地区拼音首字母-->
<!--                </label>-->
<!--                <div class="layui-input-block">-->
<!--                    <input type="text" name="pinYinAcronym" id="pinYinAcronym" lay-verify="required|pinYinAcronym"-->
<!--                           lay-verType="tips"-->
<!--                           th:value="${p.pinYinAcronym}"-->
<!--                           placeholder="请输入地区拼音首字母" autocomplete="off" class="layui-input">-->
<!--                </div>-->
<!--            </div>-->
            <div class="layui-form-item custom-text-align"
                 sec:authorize="hasPermission(#authorization.authentication,'button','DISTRICT_LIST_MANAGEMENT:edit')">
                <a class="layui-btn" lay-submit="" lay-filter="districtFormEditSubmit">保存</a>
            </div>
        </form>
    </div>
</div>

<div th:replace="~{segmentation/_tail::_tail_common}"></div>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script th:inline="javascript">
    /*<![CDATA[*/
    [# sec:authorize="hasPermission(#authorization.authentication,'button','DISTRICT_LIST_MANAGEMENT:edit')"]
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer;


        //自定义验证规则
        form.verify({
            // level: function (value) {
            //     if (value.length > 10) {
            //         return '等级最多10个字符';
            //     }
            // },
            // parentCode: function (value) {
            //     if (value.length > 255) {
            //         return '上级区划编码最多255个字符';
            //     }
            // },
            // code: function (value) {
            //     if (value.length > 255) {
            //         return '区划编码最多255个字符';
            //     }
            // },
            name: function (value) {
                if (value.length > 255) {
                    return '区划名称最多255个字符';
                }
            },
            pinYin: function (value) {
                if (value.length > 512) {
                    return '地区全拼音最多512个字符';
                }
            },
            initial: function (value) {
                if (value.length > 8) {
                    return '区域第一个字的首字母最多8个字符';
                }
            },
            pinYinAcronym: function (value) {
                if (value.length > 32) {
                    return '地区拼音首字母最多32个字符';
                }
            },
        });

        //监听提交
        form.on('submit(districtFormEditSubmit)', function (data) {
            $.ajax({
                type: 'POST',
                url: '/common/district/edit',
                data: data.field,
                dataType: 'json',
                success: function (data) {
                    if (data.code == Result.SUCCESS) {
                        layer.msg('成功!', {
                            icon: 1,
                            shade: [0.3, '#f5f5f5'],
                            time: 1500
                        }, function () {
                            $("#districtList", window.parent.document).attr('value', 1);
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 3000
                        });
                    }
                }, error:function(data) {
                    console.log(data);
                },
            });
            return false;//返回false防止重复提交
        });
    });
    [/]
    /*]]>*/
</script>

</body>
</html>